
import 'package:flutter/material.dart';
import 'package:luckin_demo/utils/global.dart';

import '../../../mock/goods_list.dart';

class GoodsListRow extends StatelessWidget {
  final bool? border;
  final String activeDesc;
  final Function onPress;
  final MockGoods data;

  /// 创建商品
  ///
  /// ```
  /// @param {bool} border - 是否显示底部的border
  /// @param {String} activeDesc - 活动描述
  /// @param {Function} onPress - 点击添加按钮
  /// @param {GoodsListDatum} data
  /// ```
  GoodsListRow({super.key, this.border = true, required this.activeDesc, required this.onPress, required this.data});
  /// 商品信息中的文本
  ///
  /// ```
  /// @param {String} title - 标题
  /// @param {double} fontSize
  /// @param {FontWeight} fontWeight
  /// @param {Color} color
  /// ```
  Widget row(String title,
      {double fontSize = 11,  FontWeight? fontWeight, Color? color}) {
    return Row(
      children: <Widget>[
        Expanded(
          child: Text(
            title,
            overflow: TextOverflow.ellipsis,
            style: TextStyle(
              color: color == null ? Color.fromRGBO(166, 166, 166, 1) : color,
              fontSize: fontSize,
              fontWeight: fontWeight == null ? FontWeight.normal : fontWeight,
            ),
          ),
        )
      ],
    );
  }
  /// 商品图片
  Widget goodsImg(String imgSrc) {
    return ClipRRect(
      borderRadius: new BorderRadius.circular(4.0),
      child: Image.network(
        imgSrc,
        width: 70,
        height: 70,
        fit: BoxFit.cover,
      ),
    );
  }
  ///活动信息
  Widget activeMsg({String? text}) {
    return text == null
        ? Container()
        : Positioned(
      right: 0,
      bottom: 5,
      child: Container(
        height: 16,
        padding: EdgeInsets.symmetric(horizontal: 4),
        alignment: Alignment.center,
        decoration: BoxDecoration(
            borderRadius: new BorderRadius.circular(2.0),
            color: Color.fromRGBO(255, 129, 2, 1)),
        child: Text(
          text,
          style: TextStyle(color: Colors.white, fontSize: 8),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        Expanded(child: Container(
          padding: EdgeInsets.symmetric(vertical: 10),
          decoration: BoxDecoration(
            border: cuBorderBottom(show: border!)  ,
          ),
          child: Row(
            children: [
              Container(
                width: 80,
                height: 70,
                child: Stack(
                  children: <Widget>[
                    Positioned(
                      child: goodsImg(data.pic!),
                    ),
                    activeMsg(text: activeDesc)
                  ],
                ),
              ),
             Expanded(child: Container(
               margin: EdgeInsets.only(left: 4),
               child: Column(
                 children: [
                   row(data.name!,
                       color: Color.fromRGBO(56, 56, 56, 1),
                       fontSize: 15,
                       fontWeight: FontWeight.bold),
                   row(data.characteristic!.isEmpty
                       ? ''
                       : data.characteristic!),
                   row(""),
                   //加入购物车和价格
                   Container(
                     margin: EdgeInsets.only(top: 4),
                     child: Row(
                       mainAxisAlignment: MainAxisAlignment.spaceBetween,
                       crossAxisAlignment: CrossAxisAlignment.center,
                       children: <Widget>[
                         Text(
                           "¥ ${data.originalPrice}",
                           style: TextStyle(
                               color: Color.fromRGBO(56, 56, 56, 1),
                               fontSize: 15,
                               fontWeight: FontWeight.bold),
                         ),
                         InkWell(
                             child: Container(
                               width: 25,
                               height: 25,
                               child: Icon(
                                 Icons.add_circle,
                                 color: Color.fromRGBO(136, 175, 213, 1),
                                 size: 25,
                               ),
                             ),
                             onTap: () {
                               if (onPress != null) {
                                 onPress(context);
                               }
                             })
                       ],
                     ),
                   )
                 ],
               ),
             ))
            ],
          ),
        ))
      ],
    );
  }
}
